#include "StdAfx.h"
#include "DisplayTest.h"

DisplayTest::DisplayTest(void)
{
}

DisplayTest::~DisplayTest(void)
{
}

//----------------------------------------------------------------
// MyCreateHatchBrush - Creates hatched brushes
//
HBRUSH DisplayTest::CreateHatchBrush(INT fnStyle, COLORREF clrref) 
{
    BRUSHBMP brbmp;
    BYTE *pBytes;
    int i;
    DWORD dwBits[6][2] = {
        {0x000000ff,0x00000000}, {0x10101010,0x10101010},
        {0x01020408,0x10204080}, {0x80402010,0x08040201},
        {0x101010ff,0x10101010}, {0x81422418,0x18244281},
    };

    memset (&brbmp, 0, sizeof (brbmp));

    brbmp.bmi.biSize = sizeof (BITMAPINFOHEADER);
    brbmp.bmi.biWidth = 8;
    brbmp.bmi.biHeight = 8;
    brbmp.bmi.biPlanes = 1;
    brbmp.bmi.biBitCount = 1;
    brbmp.bmi.biClrUsed = 2;
    brbmp.bmi.biClrImportant = 2;

    // Initialize the palette of the bitmap.
    brbmp.dwPal[0] = PALETTERGB(0xff,0xff,0xff);
    brbmp.dwPal[1] = PALETTERGB((BYTE)((clrref >> 16) & 0xff),
                                (BYTE)((clrref >> 8) & 0xff),
                                (BYTE)(clrref & 0xff));

    // Write the hatch data to the bitmap.  
    pBytes = (BYTE *)&dwBits[fnStyle];
    for (i = 0; i < 8; i++)
        brbmp.bBits[i*4] = *pBytes++;

    // Return the handle of the brush created.
    return CreateDIBPatternBrushPt (&brbmp, DIB_RGB_COLORS);
}
//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DisplayTest::PaintTest(HWND hwnd)
{
    HDC hdc;
    POINT ptArray[6];
    HBRUSH hBr, hOldBr;
    TCHAR szText[128];
	HWND hWnd;

	hdc = GetDC(hWnd);

    // Draw ellipse.
    hBr = (HBRUSH) GetStockObject (DKGRAY_BRUSH);
    hOldBr = (HBRUSH) SelectObject (hdc, hBr);
    Ellipse (hdc, 10, 50, 90, 130);
    SelectObject (hdc, hOldBr);

    // Draw round rectangle.
    hBr = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
    hOldBr = (HBRUSH) SelectObject (hdc, hBr);
    RoundRect (hdc, 95, 50, 150, 130, 30, 30);
    SelectObject (hdc, hOldBr);

    // Draw hexagon using Polygon. 
    hBr = (HBRUSH) GetStockObject (WHITE_BRUSH);
    hOldBr = (HBRUSH) SelectObject (hdc, hBr);
    ptArray[0].x = 192;
    ptArray[0].y = 50;
    ptArray[1].x = 155;
    ptArray[1].y = 75;
    ptArray[2].x = 155;
    ptArray[2].y = 105;
    ptArray[3].x = 192;
    ptArray[3].y = 130;
    ptArray[4].x = 230;
    ptArray[4].y = 105;
    ptArray[5].x = 230;
    ptArray[5].y = 75;

    Polygon (hdc, ptArray, 6);
    SelectObject (hdc, hOldBr);

    hBr = (HBRUSH) CreateHatchBrush (HS_DIAGCROSS, RGB (0, 0, 0));
    hOldBr = (HBRUSH) SelectObject (hdc, hBr);
    Rectangle (hdc, 10, 145, 225, 210);
    SelectObject (hdc, hOldBr);
    DeleteObject (hBr);

    SetBkMode (hdc, OPAQUE);
    lstrcpy (szText, TEXT ("Opaque background"));
    ExtTextOut (hdc, 20, 160, 0, NULL, 
                szText, lstrlen (szText), NULL);

    SetBkMode (hdc, TRANSPARENT);
    lstrcpy (szText, TEXT ("Transparent background"));
    ExtTextOut (hdc, 20, 185, 0, NULL,
                szText, lstrlen (szText), NULL);

    return 0;
}
